package com.gjy.pulsar.disruptor;

import com.lmax.disruptor.YieldingWaitStrategy;
import com.lmax.disruptor.dsl.Disruptor;
import com.lmax.disruptor.dsl.ProducerType;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author gjy
 * @version 1.0
 * @since 2025-08-06 12:18:37
 */
public class DisruptorBootstrapper {

    public static Disruptor<PulsarMessageEvent> startDisruptor() {
        // 1. 初始化配置
        ExecutorService executor = Executors.newCachedThreadPool();
        int bufferSize = 1024 * 1024; // 2^20

        // 2. 创建Disruptor实例
        Disruptor<PulsarMessageEvent> disruptor = new Disruptor<>(
                PulsarMessageEvent::new,
                bufferSize,
                executor,
                ProducerType.MULTI, // 支持多生产者
                new YieldingWaitStrategy() // 高性能等待策略
        );

        // 4. 启动Disruptor
        return disruptor;
    }

}
